#pragma once
#include "Couple.h"

class CouplesList
{
	friend class Dating;

private:
	List<Couple> couplesList;
	Couple couple;
	
public:
	CouplesList(CouplesList &cl)
	{
		this->couplesList = cl.couplesList;
		this->couple = cl.couple;
	}

	CouplesList & operator=(CouplesList &cl)
	{
		this->couplesList = cl.couplesList;
		this->couple = cl.couple;
		return *this;
	}

	CouplesList(void){}
	~CouplesList(void){}

	void add(Couple &c)
	{
		Element<Couple> *cPtr = couplesList.head;
		Element<Couple> *prev = nullptr;
		if(couplesList.head == nullptr)
			couplesList.head = couplesList.tail = new Element<Couple>(c);
		else
		{
			Element<Couple> *e = new Element<Couple>(c);
			while(cPtr != nullptr)
			{
				if(c.P1.name > cPtr->element_info.P1.name)
				{
					if(cPtr->element_info.P1.name == couplesList.head->element_info.P1.name)
					{
						e -> next = cPtr;
						couplesList.head = e;
						break;
					}
					else
					{
						prev -> next = e;
						e -> next = cPtr;
						break;
					}
				}
				else if(c.P1.name == cPtr->element_info.P1.name)
				{
					e->next = cPtr->next;
					cPtr->next = e;
					break;
				}
				else if((c.P1.name < cPtr->element_info.P1.name) && (cPtr->next == nullptr))
				{
					e->next = nullptr;
					cPtr->next = e;
					break;
				}
				else
				{
					prev = cPtr;
					cPtr = cPtr->next;
				}
			}
		}
	}

	void printList()
	{
		Element<Couple> *cPtr = couplesList.head;
		cout << "Couples in the list: " << endl;
		while (cPtr != nullptr)
		{
			cout << cPtr->element_info.P1.name << "-" << cPtr->element_info.P2.name << endl;
			cPtr = cPtr->next;
		}
		cout << endl;
	}
				

};